﻿// Decompiled with JetBrains decompiler
// Type: TaleWorlds.CampaignSystem.LogEntries.BesiegeSettlementLogEntry
// Assembly: TaleWorlds.CampaignSystem, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: E85F8C15-4DF6-4E9C-A58A-29177E40D07A
// Assembly location: D:\steam\steamapps\common\Mount & Blade II Bannerlord\bin\Win64_Shipping_Client\TaleWorlds.CampaignSystem.dll

using Helpers;
using System.Collections.Generic;
using TaleWorlds.CampaignSystem.Party;
using TaleWorlds.CampaignSystem.Settlements;
using TaleWorlds.Core;
using TaleWorlds.Localization;
using TaleWorlds.ObjectSystem;
using TaleWorlds.SaveSystem;

#nullable disable
namespace TaleWorlds.CampaignSystem.LogEntries
{
  public class BesiegeSettlementLogEntry : LogEntry, IEncyclopediaLog, IChatNotification, IWarLog
  {
    [SaveableField(50)]
    public readonly Hero BesiegerHero;
    [SaveableField(51)]
    public readonly Settlement Settlement;
    [SaveableField(53)]
    public readonly IFaction BesiegerFaction;
    [SaveableField(54)]
    private readonly bool _isBesiegerArmy;

    internal static void AutoGeneratedStaticCollectObjectsBesiegeSettlementLogEntry(
      object o,
      List<object> collectedObjects)
    {
      ((LogEntry) o).AutoGeneratedInstanceCollectObjects(collectedObjects);
    }

    protected override void AutoGeneratedInstanceCollectObjects(List<object> collectedObjects)
    {
      base.AutoGeneratedInstanceCollectObjects(collectedObjects);
      collectedObjects.Add((object) this.BesiegerHero);
      collectedObjects.Add((object) this.Settlement);
      collectedObjects.Add((object) this.BesiegerFaction);
    }

    internal static object AutoGeneratedGetMemberValueBesiegerHero(object o)
    {
      return (object) ((BesiegeSettlementLogEntry) o).BesiegerHero;
    }

    internal static object AutoGeneratedGetMemberValueSettlement(object o)
    {
      return (object) ((BesiegeSettlementLogEntry) o).Settlement;
    }

    internal static object AutoGeneratedGetMemberValueBesiegerFaction(object o)
    {
      return (object) ((BesiegeSettlementLogEntry) o).BesiegerFaction;
    }

    internal static object AutoGeneratedGetMemberValue_isBesiegerArmy(object o)
    {
      return (object) ((BesiegeSettlementLogEntry) o)._isBesiegerArmy;
    }

    public bool IsVisibleNotification => true;

    public BesiegeSettlementLogEntry(MobileParty besiegerParty, Settlement settlement)
    {
      this.BesiegerHero = besiegerParty.Party.Owner;
      this.Settlement = settlement;
      this._isBesiegerArmy = besiegerParty.Army != null;
      this.BesiegerFaction = besiegerParty.MapFaction;
    }

    public override string ToString() => this.GetEncyclopediaText().ToString();

    public bool IsRelatedToWar(StanceLink stance, out IFaction effector, out IFaction effected)
    {
      IFaction faction1 = stance.Faction1;
      IFaction faction2 = stance.Faction2;
      effector = this.BesiegerFaction;
      effected = this.Settlement.MapFaction;
      if (this.BesiegerFaction == faction1 && this.Settlement.MapFaction == faction2)
        return true;
      return this.BesiegerFaction == faction2 && this.Settlement.MapFaction == faction1;
    }

    public TextObject GetNotificationText()
    {
      TextObject notificationText = new TextObject("{=E20BBKYo}{TOWN_NAME} has been besieged by {FACTION_NAME}.");
      notificationText.SetTextVariable("TOWN_NAME", this.Settlement.EncyclopediaLinkWithName);
      notificationText.SetTextVariable("FACTION_NAME", this.BesiegerFaction.EncyclopediaLinkWithName);
      return notificationText;
    }

    public bool IsVisibleInEncyclopediaPageOf<T>(T obj) where T : MBObjectBase
    {
      return (object) obj == this.BesiegerHero || (object) obj == this.Settlement;
    }

    public TextObject GetEncyclopediaText()
    {
      TextObject parent = !this._isBesiegerArmy ? GameTexts.FindText("str_party_besieging_news_with_link") : GameTexts.FindText("str_army_besieging_news_with_link");
      parent.SetTextVariable("TOWN_NAME", this.Settlement.EncyclopediaLinkWithName);
      parent.SetTextVariable("FACTION_NAME", this.BesiegerFaction.EncyclopediaLinkWithName);
      StringHelpers.SetCharacterProperties("LORD", this.BesiegerHero.CharacterObject, parent);
      return parent;
    }
  }
}
